﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ECommerce.BLL.Order;
using ECommerce.Model.Order;
using Jzy.Core.Common.Web;
using Jzy.Core.Utility;
using System.Web.UI.HtmlControls;
using ECommerce.BLL.Product;
using ECommerce.Common;

namespace ECommerce.Web.Site
{
    public partial class MemberOrderDetail :SitePage
    {
        private string _pkid;
        private string PKID
        {
            get
            {
                if (Request["ID"] != null)
                {
                    if (_pkid == null)
                    {
                        _pkid = StrUtil.DecryptUrl(Request["ID"]);
                    }
                    return _pkid;
                }
                else
                {
                    return null;
                }
            }
        }

        private ECOrderBO Order
        {
            get
            {
                return ECOrderBO.Instance<ECOrderBO>();
            }
        }

        private ECProductCommentBO ProductComment
        {
            get
            {
                return ECProductCommentBO.Instance<ECProductCommentBO>();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            base.CheckLogin();
            if (string.IsNullOrEmpty(this.PKID))
            {
                Response.Redirect("MemberOrder.aspx");
            }
            DispInfo();
        }

        private OrderState _orderState;
        private void DispInfo()
        {
            ECOrderInfo info = Order.GetInfo(this.PKID);
            _orderState = (OrderState)info.OrderState;
            EntityUtil.SetControl(pnlMain, info);

            this.litOrderID.Text = info.ID.ToString();
            this.litPayState.Text = ((PayState)info.PayState).ToString();
            this.litPayMode.Text = ((PayMode)info.PayMode).ToString();
            this.litFreight.Text = info.Freight.ToString("c2");
            this.litTradeValue.Text = info.TradeValue.ToString("c2");
            this.litTotal.Text = (info.Freight + info.TradeValue).ToString("c2");
            this.litOrderState.Text = ((OrderState)info.OrderState).ToString();
            this.litInvoiceHead.Text = ((InvoiceTarget)info.InvoiceTarget).ToString();
            this.DeliverTime.Text = info.DeliverTime.ToString("yyyy-MM-dd");
            if (info.InvoiceTarget == (int)InvoiceTarget.单位)
            {
                this.litInvoiceHead.Text += "&nbsp;(" + info.InvoiceHead + ")";
            }
            this.RecieveArea.Text = "[" + info.RecieveArea + "]";
            //this.SendArea.Text = "[" + info.SendArea + "]";
            this.litBigArea.Text = "[" + ((BigArea)info.BigArea).ToString() + "]";
            this.litReceiveBigArea.Text = "[" + ((BigArea)info.RecieveBigArea).ToString() + "]";
            this.DeliverPart.Text = "[" + info.DeliverPart + "]";

            if (string.IsNullOrEmpty(info.Remark))
            {
                this.Remark.Text = "无";
            }
            else
            {
                this.Remark.Text = info.Remark;
            }

            if (info.LogisticsType == (int)LogisticType.门店自取)
            {
                Panel1.Visible = false;
                Panel2.Visible = true;
            }
            else
            {
                Panel1.Visible = true;
                Panel2.Visible = false;
            }

            rpt.DataSource = info.Products;
            rpt.DataBind();
        }

        protected string GetJs(object productID)
        {
            return "javascript:showForm('会员注册','Comment.aspx?ProductID=" + productID + "',497,352)";
        }

        protected void rpt_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                ECOrderProductInfo info = e.Item.DataItem as ECOrderProductInfo;
               // bool hasComment = ProductComment.HasComment(info.ProductID, SiteSession.MemberID);
                HtmlAnchor lnkComment = e.Item.FindControl("lnkComment") as HtmlAnchor;
                if (_orderState != OrderState.已结束 )
                {
                    lnkComment.Visible = false;
                }
            }
        }
    }
}